package com.airsystem.pos.bengkel.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.ForeignKey;

/**
 * @author Budi Oktaviyan <budi.oktaviyan@icloud.com>
 */

@Entity
@Table(name = "tbl_detail_kendaraan")
public class DetailKendaraan implements Serializable {

	@Transient
	public static final String ALIAS = "detail_kendaraan";

	@Id
	@Column(unique = true, nullable = false)
	private String sub_merk;

	@ManyToOne
	@ForeignKey(name = "FK_KENDARAAN")
	private Kendaraan kendaraan;

	@OneToMany(mappedBy = "detail_kendaraan", fetch = FetchType.LAZY)
	private Set<DetailSparepart> sparepart_kendaraan = new HashSet<DetailSparepart>(0);

	@OneToMany(mappedBy = "detail_kendaraan", fetch = FetchType.LAZY)
	private Set<DetailLayanan> layanan_kendaraan = new HashSet<DetailLayanan>(0);

	@OneToMany(mappedBy = "detail_kendaraan", fetch = FetchType.LAZY)
	private Set<DetailPelanggan> pelanggan_kendaraan = new HashSet<DetailPelanggan>(0);

	public String toString() {
		StringBuffer sb = new StringBuffer(kendaraan.getMerk());
		sb.append(" - ");
		sb.append(sub_merk);

		return sb.toString();
	}

	public String getSub_merk() {
		return sub_merk;
	}

	public void setSub_merk(String sub_merk) {
		this.sub_merk = sub_merk;
	}

	public Kendaraan getKendaraan() {
		return kendaraan;
	}

	public void setKendaraan(Kendaraan kendaraan) {
		this.kendaraan = kendaraan;
	}

	public Set<DetailSparepart> getSparepart_kendaraan() {
		return sparepart_kendaraan;
	}

	public void setSparepart_kendaraan(Set<DetailSparepart> sparepart_kendaraan) {
		this.sparepart_kendaraan = sparepart_kendaraan;
	}

	public Set<DetailLayanan> getLayanan_kendaraan() {
		return layanan_kendaraan;
	}

	public void setLayanan_kendaraan(Set<DetailLayanan> layanan_kendaraan) {
		this.layanan_kendaraan = layanan_kendaraan;
	}

	public void addDetail_Layanan(DetailLayanan detailLayanan) {
		this.layanan_kendaraan.add(detailLayanan);
	}

	public Set<DetailPelanggan> getPelanggan_kendaraan() {
		return pelanggan_kendaraan;
	}

	public void setPelanggan_kendaraan(Set<DetailPelanggan> pelanggan_kendaraan) {
		this.pelanggan_kendaraan = pelanggan_kendaraan;
	}
}